<?php
/**
 * Created by PhpStorm.
 * User: 会吃草的鱼
 * Date: 2016-08-09
 * Time: 11:33
 */
namespace Admin\Controller;
use Recruit\Api\UcenterMemberApi;
use Recruit\Api\CompanyApplyApi;
use Recruit\Api\ProjectApi;

class projectController extends AdminController {
    /*
     * 项目查看以新页面打开
     * */
    public function look(){
        $map['id'] = I('id');
        $findres = apiCall(ProjectApi::GET_INFO,array($map));
        if($findres['status']){
            $findres['info']['detail'] = htmlspecialchars_decode($findres['info']['detail']);
            $this->assign($findres['info']);
        }
        $this->display();
    }

    /*
     * 添加项目
     * */
    public function add(){
        if(IS_POST){
            $entity = array(
                'title' => I('title'),
                'summary' => I('summary'),
                'detail' => I('detail'),
                'create_time' => time(),
                'come_from' => I('come_from'),//项目来源
                'uid' => UID,
            );
            $addres = apiCall(ProjectApi::ADD,array($entity));
            if($addres['status']){
                $this->success('项目添加成功',U('Project/user_list'));
            }else{
                $this->error('项目添加失败');
            }
        }else{
            $this->display();
        }
    }
    /*
     * 投过的项目列表 需要连表查询
     * */
    public function apply(){
        $map['itboye_project_apply.uid'] = UID;
        $queryres = apiCall(ProjectApi::QUERY_JOIN,array($map,'','apply_time desc',$map,'itboye_project.id,itboye_project.title,itboye_project.come_from,itboye_project_apply.apply_time'));
        if($queryres['status']){
            $this->assign('list',$queryres['info']['list']);
            $this->assign('show',$queryres['info']['show']);
        }
        $this->display();
    }
    /*
     * Ajax投过的项目删除
     * */
    public function delete_apply(){

    }

    /*
     * 用户自己项目列表
     * */
    public function user_list(){
        $map['uid'] = UID;
        $info = apiCall(ProjectApi::QUERY,array($map));
        if($info['status']){
            $this->assign('uid',UID);
            $this->assign('list',$info['info']['list']);
            $this->assign('show',$info['info']['show']);
        }
        $this->display();
    }

    /*
     * 所有用户发布的项目列表
     * */
    public function all_list(){
        $info = apiCall(ProjectApi::QUERY);
        if($info['status']){
            $this->assign('list',$info['info']['list']);
            $this->assign('show',$info['info']['show']);
        }
        $this->display();
    }

    /*
     * 项目重新编辑和接收保存
     * */

    public function edit(){
        $map['id'] = I('id');
        if(IS_POST){
            $info = apiCall(ProjectApi::SAVEBYID,array($map['id']));
            if($info['status']){
                $this->success('修改成功',U('Project/user_list'));
            }else{
                $this->error('修改失败');
            }
        }else{
            $findres = apiCall(ProjectApi::GET_INFO,array($map));
            if($findres['status']){
                $findres['info']['detail'] = htmlspecialchars_decode($findres['info']['detail']);
                $this->assign($findres['info']);
            }
            $this->display();
        }

    }

    /*
     * 项目的删除
     * */
    public function delete(){
        $map['id'] = I('id');
        $deleteres = apiCall(ProjectApi::DELETE,array($map));
        if($deleteres['status']){
            $this->success('删除成功');
        }else{
            $this->error('删除失败');
        }
    }

    /*所有项目中搜索和自己发布的项目搜索*/
    public function search_project(){
        $map['title'] = array('like','%'.I('name').'%');
        if(!empty(I('uid'))){
            $map['uid'] = I('uid');
        }
        $infores = apiCall(ProjectApi::QUERY,array($map));
        if($infores['status']){
            $this->assign('name',I('name'));
            $this->assign('list',$infores['info']['list']);
            $this->assign('show',$infores['info']['show']);
        }
        $this->display();
    }
    /*
     * 搜索自己投过的项目
     * */
    public function search_self_project(){
        $map['itboye_project_apply.uid'] = UID;
        $map['title'] = array('like','%'.I('name').'%');
        $infores = apiCall(ProjectApi::QUERY_JOIN,array($map));
        if($infores['status']){
            $this->assign('list',$infores['info']['list']);
            $this->assign('show',$infores['info']['show']);
        }
        $this->display();
    }
}